<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>首页-接口测试</title>
	<script type="text/javascript" src="static/js/jquery.2.0.js"></script>
    <script type="text/javascript" src="static/js/jquery.cookie.js"></script>
	<style>
		*{padding: 0px;margin: 0px;}
		body{padding-top: 2em;}
		div.divmain{width: 1280px;margin: 0 auto;}
		div.div1{margin: 2em 1em;width: 550px;border: 1px solid #CCC;border-radius: 3px;float: left;}
		div.div2{padding: 10px 0px;border-bottom: 1px solid #CCC;}
		div.div3,div.div4{float: left;line-height: 24px;}
		div.div3{width: 120px;text-align: right;}
		div.div4{text-align: left;text-indent: 10px;}
		input.dfinput{width: 404px;height: 24px;line-height: 18px;}
		input.dfbutton{padding: 5px 10px;height: 26px;line-height: 16px;}
		div.div5{padding: 2em;text-align: center;}
		div.clearAll{clear: both;}
		div.div6{float: left;margin: 2em 1em;width: 630px;}
		#outPut{height: 468px;width: 630px;}
	</style>
	<script>
		var cookie_code;
		function readOld(){
			var a = $.cookie('textAction');
			var b = $.cookie('textParam');
			if(a){
				$('input.interAction').val(a);
			}
			if(b){
				$('textarea.interParam').val(b);
			}
		}
		$(function(){
			readOld();
			$('input.dfbutton').on('click',function(){
				var action = $('input.interAction').val();
				var param = $('textarea.interParam').val();
				$.cookie('textAction',action);
				$.cookie('textParam',param);
				if(param){
					//param = eval('(' + param + ')');
				}else{
					param = {};
				}
//				param=JSON.parse(param);
				var init={
					type: 'POST',
					url: action,
					data: {'data':param},
					dataType: "json",
					success: function(e){
						var outPut = $('#outPut');
						outPut.val('');
						str = '状态码：' + e.code + '\r\n';
						str += '提示信息：' + e.msg + '\r\n\r\n';
						if(e.result){
							if(action=='index/index/check_sms'){
								$.cookie('uid',e.result);
							}
							str += JSON.stringify(e.result);
						}
						outPut.val(str);
					},
				}
//				var uid=$.cookie('uid');
//				if(uid){
//					init['headers']={
//						'content-type': 'application/x-www-form-urlencoded',
//        				'X-Requested-With': 'XMLHttpRequest',
//						'Cookie': 'uid=' + uid
//					};
//				}
				$.ajax(init);
//				$.post(action, {'data':param}, function(e){
//					var outPut = $('#outPut');
//					outPut.val('');
//					str = '状态码：' + e.code + '\r\n';
//					str += '提示信息：' + e.msg + '\r\n\r\n';
//					if(e.result){
//						if(e.result.msg=='登录成功' || e.result.msg=='注册成功'){
//							$.cookie('uid',e.result.rel);
//						}
//						str += JSON.stringify(e.result);
//					}
//					outPut.val(str);
//				},"json");
				
			});
		});
	</script>
</head>
<body>
	<div class="divmain">
		<div class="div1">
			<div class="div2">
				<div class="div3">Action：</div>
				<div class="div4">
					<input type="text" class="dfinput interAction">
				</div>
				<div class="clearAll"></div>
			</div>
			<div class="div2">
				<div class="div3">JSON数据：</div>
				<div class="div4">
					<textarea class="interParam" cols="55" rows="20"></textarea>
				</div>
				<div class="clearAll"></div>
			</div>
			<div class="div5">
				<input type="button" class="dfbutton" value="提交">
			</div>
		</div>
		<div class="div6">
			<textarea id="outPut"></textarea>
		</div>
		<div class="clearAll"></div>
	</div>
</body>
</html>